package com.kupurui.asteacher.ui.mine.message;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.adapter.NoticeMessageAdapter;
import com.kupurui.asteacher.bean.NoticeMessageInfo;
import com.kupurui.asteacher.http.MessageReq;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.utils.UserManger;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 通知消息
 * Created by Administrator on 2017/7/17.
 */

public class NoticeMessageAty extends BaseAty {

    @Bind(R.id.tv_bar_title)
    TextView tvBarTitle;
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.listview)
    ListView listView;

    List<NoticeMessageInfo.MessageBean> list;
    NoticeMessageAdapter adapter;
    NoticeMessageInfo noticeMessageInfo;

    @Override
    public int getLayoutId() {
        return R.layout.notice_message_aty;
    }

    @Override
    public void initData() {
        initToolbar(mToolbar,"通知消息");
        list = new ArrayList<>();
        adapter = new NoticeMessageAdapter(this,list,R.layout.notice_messgae_item);
        listView.setAdapter(adapter);
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new MessageReq().info_message(UserManger.getId(),this,0);
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what){
            case 0:
                noticeMessageInfo = AppJsonUtil.getObject(result,NoticeMessageInfo.class);
                list.clear();
                list.addAll(noticeMessageInfo.getMessage());
                adapter.notifyDataSetChanged();
                break;
        }
        super.onSuccess(result, call, response, what);
    }
}
